﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.EzAppApi.Utility;
using EzDesk.EzAppApi.Utility.EzDeskAppApi;

namespace EzDesk.Message.Service
{
    public class PersonService
    {
        #region [ 构造器 ]
        private EzApiClient apiClient;

        public PersonService(EzApiClient apiClient)
        {
            this.apiClient = apiClient;
        }

        public PersonService()
            : this(new EzApiClient())
        {
        }
        #endregion



        public IList<SimpleUser> GetPersonsInDept(Guid? deptId)
        {
            if (deptId.HasValue && deptId.GetValueOrDefault() != Guid.Empty)
            {
                return apiClient.GetAllUsersByMemberString(
                    EzDeskAppApiHelper.MemberStringHelper.JoinGroupId(
                        "",
                        apiClient.GetDeptById(deptId.GetValueOrDefault())
                            .GroupId.GetValueOrDefault()
                        )
                        );               
            }
            else
            {
                return apiClient.GetAllUsersByMemberString("everyone");
            }
        }
    }
}
